package sanrenxing.dayEnd.backRepertoryTotal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.dao.TradingSeatDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TradingSeat;
import sanrenxing.dayEnd.backRepertoryTotal.service.TradingSeatBiz;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/tradingcrud")
public class TradingSeatController {
    /*定义业务层接口*/
    @Autowired
    private TradingSeatBiz tradingSeatBiz;

    @Autowired
    private TradingSeatDao tradingSeatDao;

    @GetMapping("/trad")
    public Map<String,Object> queryAll(int page, int limit, TradingSeat tradingSeat){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",tradingSeatBiz.count(tradingSeat));
        map.put("data",tradingSeatBiz.queryAll(tradingSeat,limit,(page-1)*limit));
        map.put("settingOfSecurities",tradingSeatDao.querySST());
        return map;
    }
    //添加数据
    @PostMapping("/trad")
    public String addFund(@RequestBody TradingSeat tradingSeat) {
        int rows=tradingSeatBiz.add(tradingSeat);
        return rows>0?"add success":"failure";
    }

    //删除数据
    @DeleteMapping("/trad/{str}")
    public String deleteFund(@PathVariable String str){
        //调用业务层删除数据
        int rows=tradingSeatBiz.delete(str);
        return rows>0?"delete success":"delete failure";
    }
    //修改数据
    @PutMapping("/trad")
    public String updateFund(@RequestBody TradingSeat tradingSeat){
        //调用业务层修改数据
        int rows=tradingSeatBiz.update(tradingSeat);
        return rows>0?"update success":"update failure";
    }
}
